'use strict';

module.exports = app => {
  function request(router, hanlder, hanlder2) {
    if (arguments.length == 2) {
      app.get(router, hanlder)
      app.post(router, hanlder)
    } else if (arguments.length == 3) {
      app.router.get(router, app.middlewares.router({ modelName: hanlder }), hanlder2)
      app.router.post(router, app.middlewares.router({ modelName: hanlder }), hanlder2)
    }
  }

  //账号登录

  app.router.get('/', 'account.home');

  //app.router.redirect('/', '/account/pc', 302);

  request('/account/:page?/:agentId?', 'account.home');
  request('(/api)?/account/loginDD', 'account.loginDD');
  request('(/api)?/account/login', 'account.login');
  request('(/api)?/account/logout', 'account.logout');
  request('(/api)?/account/async', 'account.asyncUser');

  //通用路由
  //app.router.get('/model/:name', app.controller.model.save)
  //app.router.redirect('/account/logout222', '/model/222', app.controller.model.save);

  //产品路由
  request('(/api)?/product/', 'product', 'model.find')

  //通用增删改
  request('/table', 'home.index')
  request('(/api)?/table/:table/', 'table.findAll')
  request('(/api)?/table/:table/findOne', 'table.findOne')
  request('(/api)?/table/:table/findAll', 'table.findAll')
  request('(/api)?/table/:table/page', 'table.page')
  request('(/api)?/table/:table/save', 'table.save')

  //测试接口
  request('/', 'home.index');
  request('/async', 'home.asyncUser');
  request('/init', 'home.init');
  request('/test', 'home.test');
  request('/upgrade', 'home.upgrade');

  // 报修
  request('(/api)?/repair/', 'repair.index');
  request('(/api)?/repair/add', 'repair.add');
  request('(/api)?/repair/detail', 'repair.detail');
  request('(/api)?/repair/send', 'repair.send');
  request('(/api)?/repair/receive', 'repair.receive');
  request('(/api)?/repair/do', 'repair.do');
  request('(/api)?/repair/eval', 'repair.eval');
  request('(/api)?/repair/sign', 'repair.sign');
  request('(/api)?/repair/workflow', 'repair.workflow');

  // 用户
  request('(/api)?/user/login', 'user.login');
  request('(/api)?/user/', 'user.index');
  request('(/api)?/user/detail', 'user.detail');
  request('(/api)?/user/getUserInfo', 'user.getUserInfo');
  request('(/api)?/user/setRole', 'user.setRole');

  request('(/api)?/table/:table/save', 'table.save')
  request('(/api)?/table/:table/saveMany', 'table.saveMany')
  request('(/api)?/table/:table/remove', 'table.remove')

  //文件上传
  request('(/api)?/file/upload', 'file.upload')
  request('(/api)?/file/uploadFile', 'file.uploadFile')
  request('(/api)?/file/xls', 'file.exportXls')
  request('(/api)?/file/:filename', 'file.download')

  //客户
  request('(/api)?/customer/', 'customer.index')
  request('(/api)?/customer/save', 'customer.save')
  request('(/api)?/customer/remove', 'customer.remove')
  request('(/api)?/customer/getCustomerSaleInfo', 'customer.getCustomerSaleInfo')

  //客户联系人
  request('(/api)?/contact/', 'contact', 'contact.page')
  request('(/api)?/contact/save', 'contact', 'model.save')
  request('(/api)?/contact/remove', 'contact', 'model.remove')

  //客户拜访
  request('(/api)?/visit/page', 'visit.page')
  request('(/api)?/visit/save', 'visit.save')
  request('(/api)?/visit/remove', 'visit.remove')

  /*** 批次和产品 路由表 ***/
  request('(/api)?/batch/product', 'batch_product', 'model.find')  //查询批次相关产品
  request('(/api)?/batch/page', 'batch.page')  //批次列表分页查询
  request('(/api)?/batch/getBatchAndProduct', 'batch.getBatchAndProduct')  //获取批次及产品
  request('(/api)?/batch/save', 'batch.save')  //保存批次
  request('(/api)?/batch/remove', 'batch.remove')  //删除批次
  request('(/api)?/batch/publish', 'batch.publish') //发布批次
  request('(/api)?/batch/:oid', 'batch_product', 'model.findById')  //根据主键查询批次信息

  //项目
  request('(/api)?/project', 'project.page')
  request('(/api)?/project/save', 'project.save')
  request('(/api)?/project/remove', 'project.remove')

  //角色权限
  request('(/api)?/role/powerList', 'role.powerList')
  request('(/api)?/role/getPower', 'role.getPower')
  request('(/api)?/role/savePower', 'role.savePower')


};
